<template>
	<div class="cockpit-main">	
		<section class="section-item">	
			<dy-select></dy-select>
		</section>
		<section class="section-item">	
			<div class="title">实时数据 <div class="time fr">截止时间：{{upData.createTime}}</div></div>
			<dy-up :isClick='false' :opt="upData.list"></dy-up>
		</section>
		<section class="section-item">
			<div class="title">业绩达成 <div class="time fr">截止时间：{{majorTime}}</div></div>	
			<div class="cc">
				<div class="item-part">
					<chart :options="gauge1" theme="roma"></chart>	
					<div class="gauge-name">新增授信完成率</div>
				</div>
				<div class="item-part">
					<chart :options="gauge2" theme="roma"></chart>				
					<div class="gauge-name">在库净增完成率</div>
				</div>
			</div>
		</section>
		<section class="section-item">	
			<dy-money :opt="moneyData" :isClick='false'></dy-money>
		</section>
	</div>
</template>
<script>
import dicts from '@/utils/dicts'
import {merge} from '@/utils/index'
export default {
	name: 'allIndex',
	data () {	 
		return {	
			upData: [],
			gauge1: {},
			gauge2: {},
			moneyData: {
				row: 3,
				layoutType: 'horizontal',
				api: 'cockpitMajor',
				dict: dicts.dictLoans,
				dateList: dicts.dictDate	
			},	
			majorTime: ''    
		}
	},
	computed : {
		orgId ()  {
			return this.$store.getters.orgId
		}
	},
	watch : {
		orgId ()  {
			this.updata();
		}
	},	
	methods: {
    	// 更新数据
    	updata () {    		
    		this.getActualMajor();
    		this.getAchievementMajor();
    	},    	
    	// 指标实时涨跌报表
    	getActualMajor () {
            if(!this.orgId) return

    		api.actualMajor({orgId: this.orgId}).then(data => {   
    			this.upData = {
    				list: [
    				{
    					name: '新增借款',
    					value: data.loanAmount,
    					diff: data.loanAmountDiff,
    				},{
    					name: '还款本金',
    					value: data.repayCapital,
    					diff: data.repayDiff,
    				},{
    					name: '在库净增',
    					value: data.loanStorage,
    					diff: data.loanStorageDiff,
    				}
    				],
    				createTime: data.createTime
    			}
    		}) 
    	},    	
    	// 仪盘表
    	getAchievementMajor () {
            if(!this.orgId) return

    		api.achievementMajor({orgId: this.orgId}).then(data => {   
    			let gauge1 = {series : [ 
    				{
    					max: 150,
    					axisLine: {           
    						lineStyle: {      
    							color: [[0.8, '#e9666f'], [0.99, '#ffda69'], [1, '#5fda73']]
    						}  
    					},   
    					data : [{ name: '', value: parseFloat(data.creditCompleteRatio)}]
    				}
    			]}
    			let gauge2 = {series : [ 
    				{
    					max: 150,
    					axisLine: {           
    						lineStyle: {      
    							color: [[0.8, '#e9666f'], [0.99, '#ffda69'], [1, '#5fda73']]
    						}  
    					},   
    					data : [{ name: '', value: parseFloat(data.loanCompleteRatio)}]
    				}
    			]}
    			this.gauge1 = merge(this.gauge, gauge1)
    			this.gauge2 = merge(this.gauge, gauge2)
    			this.majorTime = data.createTime;
    		}) 
    	},    	
    }
}
</script>
<style lang="less" scope>
@import '../../assets/less/base.less';
.cockpit-main {
	.gauge-name {
		margin: -1rem 0 1rem;		
	}
}
</style>